/*
 * FollowupDisplayScreen.java
 *
 * Created on April 18, 2007, 4:42 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Experience.Screens;

import Experience.ExpUI;
import Experience.FollowupSample;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.StringItem;

/**
 *
 * @author dmgreen
 */
public class FollowupDisplayScreen extends Form implements CommandListener {
    
    private FollowupSample myFollowupSample;
    
    /** Creates a new instance of FollowupDisplayScreen */
    public FollowupDisplayScreen(FollowupSample fs) {
        super("Sample Details");
        myFollowupSample = fs;
    
        this.addCommand(new Command("Next", Command.BACK, 1));
        this.setCommandListener(this);
        
        processFollowupSample();
    }
    
    public void commandAction(Command com, Displayable dis) {
	String label = com.getLabel();
	
        if ("Next".equals(label)) {
            ExpUI.getMIDlet().notifyNext("");
        }
    }
    
    private void processFollowupSample () {
       
        int pre_glucose  = myFollowupSample.getGlucose();
        int post_glucose = myFollowupSample.getPostGlucose();
        
        byte[] sample_image = myFollowupSample.getImage(); 
        
        
        if (sample_image != null) {
            this.append( Image.createImage(sample_image,0,sample_image.length) );
        } else {
            this.append(new StringItem(null, "<no image>\r\n"));
        }
        
        if (pre_glucose == 9999) {
            this.append(new StringItem(null, "Reference BG: <not available>\r\n"));
        }
        else {
            this.append(new StringItem(null, "Reference BG: " + pre_glucose + "\r\n"));
        }
        
        if (post_glucose == 9999) {
            this.append(new StringItem(null, "Post BG: <not available>\r\n"));
        } else {
            this.append(new StringItem(null, "Post BG: "      + post_glucose + "\r\n" ));
        }
         
         if ( (post_glucose != 9999) && (pre_glucose != 9999) )  {
             this.append(new StringItem(null, "Impact: " + (post_glucose - pre_glucose) + "\r\n"));
         } else {
             this.append(new StringItem(null, "Impact: <not available>\r\n" ));
         }
     }
}
